//
//  SimplePickerViewController.m
//  SKStock
//
//  Created by thPark on 11. 1. 6..
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "SimplePickerViewController.h"

@implementation SimplePickerViewController

@synthesize dataArray = _dataArray;
@synthesize delegate = _delegate;

#pragma mark Lifetime Related

- (void)viewDidLoad {
    [super viewDidLoad];
	
	[_pickerView selectRow:_pickerIdx inComponent:0 animated:YES];
}

- (void)dealloc {
//    LOG_DEALLOC(@"======== Start");
	G__SAFE_FREE(_dataArray);
	G__SAFE_FREE(_pickerView);
	_delegate = nil;
	
    [super dealloc];
//	LOG_DEALLOC(@"======== End");
}

#pragma mark -
#pragma mark Control Actions
- (IBAction)doneButtonAction:(id)sender {
	int selectedIndex = [_pickerView selectedRowInComponent:0];
	[_delegate simplePickerViewControllerDidSelected:self selectedIndex:selectedIndex];
}

- (IBAction)cancelButtonAction:(id)sender {
	[_delegate simplePickerViewControllerDidCancelled:self];
}

#pragma mark -
#pragma mark UIPickerViewDelegate
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
	NSString * title = [_dataArray objectAtIndex:row];
//	NSDictionary * item = [_dataArray objectAtIndex:row];
//	NSString * title = [item objectForKey:@"Title"];
	return title;
}

#pragma mark -
#pragma mark UIPickerViewDataSource
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
	return 1;
}

// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
	return [_dataArray count];
}

- (void)setPickerIndex:(int)idx{
	_pickerIdx = idx;
}

@end
